package com.cskaoyan.controller.front.collect;

import com.cskaoyan.bean.po.CommonData;
import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.vo.back.BaseRespVo;
import com.cskaoyan.service.front.collect.CollectService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @author: jzc
 * @since: 2022/10/14 11:30
 **/
@RestController
@RequestMapping("wx/collect")
public class CollectController {

    @Autowired
    CollectService collectService;

    @GetMapping("list")
    public BaseRespVo collectList(Byte type,Integer page, Integer limit){
        MarketUser primaryPrincipal = (MarketUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        CommonData commonData=collectService.getCollectList(type,page,limit,primaryPrincipal);
        return BaseRespVo.ok(commonData);
    }
    @PostMapping("addordelete")
    public BaseRespVo collectAddordelete(@RequestBody Integer type,Integer valueId){
        byte type2 = type.byteValue();
        MarketUser primaryPrincipal = (MarketUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        int effected =collectService.addordelete(primaryPrincipal,type2,valueId);
        if (effected==0){
            return BaseRespVo.invalidData();
        }
        return BaseRespVo.ok();
    }
}
